#include "application.h"
#include "State_browse.h"

extern STOR_SERV_PLAYINFO browse_curr_avi;
INT8U mode_key_enabled;
extern INT8U del_mode;
#if(defined(C_ZHONGQIN_SPECIAL) && (C_ZHONGQIN_SPECIAL == CUSTOM_ON))
	#define Browse_Close_Screen_Save CUSTOM_ON
	INT8U Pre_Screen_Save_Status;
#endif

Overlap_Browse_Function  State_Browse;

void overlap_state_browse_function_initial(void)
{
	#if C_TOUCH_PANEL
	State_Browse.state_browse_init_ptr = &state_browse_init_TP;
	State_Browse.state_browse_entry_ptr= &state_browse_entry_TP;
	#else
	State_Browse.state_browse_init_ptr = &state_browse_init;
	State_Browse.state_browse_entry_ptr= &state_browse_entry;
	#endif
}

void state_browse_init(INT32U prev_state, INT16U play_index)
{
	DBG_PRINT("%s ... \r\n", __func__);
	DBG_PRINT("Browse state init enter\r\n");
	
	#if(defined(C_ZHONGQIN_SPECIAL) && (C_ZHONGQIN_SPECIAL == CUSTOM_ON))
		#if Browse_Close_Screen_Save
			Pre_Screen_Save_Status=ap_state_config_auto_off_TFT_BL_get();
			ap_state_config_auto_off_TFT_BL_set(0);
		#endif
	#endif 
	
	g_browser_reply_action_flag = 0;

	ap_browse_init(prev_state, play_index);
	browser_play_speed = 0;
}

extern INT16U browse_total_file_num;
extern INT16U value_browse_total_num();
void state_browse_entry(void *para, INT16U play_index)
{
	EXIT_FLAG_ENUM	exit_flag = EXIT_RESUME;
	INT32U			msg_id, prev_state, search_type;
	STAudioConfirm	*audio_temp;
	INT8U			func_key_act = 0;
	INT8U			temp;

	DBG_PRINT("state_browse_entry()\r\n");
	OSTimeDly(10);
	prev_state = *((INT32U *) para);
	DBG_PRINT("prev_state = 0x%08x\r\n", prev_state);
	if((prev_state == STATE_SETTING) || (prev_state == STATE_THUMBNAIL))
	{
		msgQAccept(ApQ, &msg_id, (void *) ApQ_para, AP_QUEUE_MSG_MAX_LEN);
		if(msg_id == MSG_APQ_CONNECT_TO_PC)
		{
			msgQSend(ApQ, MSG_APQ_CONNECT_TO_PC, NULL, 0, MSG_PRI_NORMAL);
			State_Browse.state_browse_init_ptr(prev_state, play_index);
		}
		else
		{
			OS_Q_DATA	data;
			msgQQuery(ApQ, &data);

			// if queue isn't empty.
			if(data.OSNMsgs != 0)
			{
				//max size of para is STAudioConfirm
				msgQSend(ApQ, msg_id, (void *) ApQ_para, sizeof(STAudioConfirm), MSG_PRI_NORMAL);
			}

			State_Browse.state_browse_init_ptr(prev_state, play_index);
		}
	}
	else
	{
		State_Browse.state_browse_init_ptr(prev_state, play_index);
	}
	DBG_PRINT("%s ... \r\n", __func__);

	while(exit_flag == EXIT_RESUME)
	{
		if(msgQReceive(ApQ, &msg_id, (void *) ApQ_para, AP_QUEUE_MSG_MAX_LEN) == STATUS_FAIL)
		{
			continue;
		}

		switch(msg_id)
		{
		case EVENT_APQ_ERR_MSG:
			audio_temp = (STAudioConfirm *) ApQ_para;
			if((audio_temp->result == AUDIO_ERR_DEC_FINISH) && (audio_temp->source_type == AUDIO_SRC_TYPE_FS))
			{
				browser_play_speed = 0;

				#if(GP_UI==General_UI )
				{
//////					ap_state_handling_icon_clear_cmd(ICON_FORWARD, ICON_BACKWARD, ICON_2X);
//					ap_state_handling_icon_clear_cmd(ICON_PLAY, ICON_PAUSE, 0);
//					ap_state_handling_icon_clear_cmd(ICON_PLAY1, ICON_PAUSE1, 0);
				}
				#endif

				if(g_AVI_resolution == AVI_RES_VGA)
				{
					#if(GP_UI == General_UI)
					{
//						ap_state_handling_icon_show_cmd(ICON_PLAY, 0, 0);
					}
					#endif
				}
				else
				{
					#if(GP_UI == General_UI)
					{
//						ap_state_handling_icon_show_cmd(ICON_PLAY1, 0, 0);
					}
					#endif
				}

				ap_browse_wav_stop();
				ap_state_audio_play_speed_set(1);
				msgQSend(StorageServiceQ, MSG_STORAGE_SERVICE_TIMER_START, NULL, 0, MSG_PRI_NORMAL);
			}
			else
			if((audio_temp->result == AUDIO_ERR_DEC_FINISH) && (audio_temp->source_type == AUDIO_SRC_TYPE_APP_RS))
			{
				//gpio_write_io(SPEAKER_EN_PIN, DATA_LOW);
				if(func_key_act)
				{
					if(g_browser_reply_action_flag)
					{
						ap_browse_func_key_active();
					}

					func_key_act = 0;
				}
			}
			else
			{
				audio_confirm_handler((STAudioConfirm *) ApQ_para);
			}

			break;

		case MSG_STORAGE_SERVICE_MOUNT:
			ap_state_handling_icon_clear_cmd(ICON_INTERNAL_MEMORY, 0, 0);
			ap_state_handling_icon_show_cmd(ICON_SD_CARD, 0, 0);
			ap_state_handling_str_draw_exit2();
			ap_state_handling_str_draw_exit1();
			ap_state_handling_storage_id_set(ApQ_para[0]);
			ap_browse_sts_set(~BROWSE_UNMOUNT);
			g_browser_reply_action_flag = 0;
			search_type = STOR_SERV_SEARCH_INIT;
			msgQSend(StorageServiceQ, MSG_STORAGE_SERVICE_BROWSE_REQ, (void *) &search_type, sizeof(INT32U), MSG_PRI_NORMAL);
			DBG_PRINT("[State Browse Mount OK]\r\n");
			
			break;

		case MSG_STORAGE_SERVICE_NO_STORAGE:
			#if C_SPI_FLASH_DISK
				ap_state_handling_storage_id_set(ApQ_para[0]);
				ap_browse_sts_set(BROWSE_UNMOUNT);
				ap_browse_stop_handle();
				g_browser_reply_action_flag = 0;
				#if(GP_UI == General_UI)
				{
					//ap_state_handling_icon_clear_cmd(ICON_PAUSE, ICON_PLAY, 0);
					//ap_state_handling_icon_clear_cmd(ICON_PLAY1, ICON_PAUSE1, 0);
					//ap_state_handling_icon_clear_cmd(ICON_PLAYBACK_PLAY, ICON_PLAYBACK_PAUSE, ICON_PLAYBACK_MOVIE);
					//ap_state_handling_icon_clear_cmd(ICON_PLAYBACK, ICON_PLAYBACK_MOVIE, 0);
					//ap_state_handling_icon_show_cmd(ICON_PLAYBACK, 0, 0);	
					ap_state_handling_icon_clear_cmd(ICON_SD_CARD, 0, 0);
					ap_state_handling_icon_show_cmd(ICON_INTERNAL_MEMORY, 0, 0);				
				}
				#endif
				
				ap_display_show_date_time(SHOW_TIME_NONE);
				ap_browse_volume_icon_clear_all();
				ap_browse_string_icon_clear();
				ap_state_handling_str_draw_exit();

				
				
				search_type = STOR_SERV_SEARCH_INIT;
				msgQSend(StorageServiceQ, MSG_STORAGE_SERVICE_BROWSE_REQ, (void *) &search_type, sizeof(INT32U), MSG_PRI_NORMAL);
			break;
		   #endif


			g_browser_reply_action_flag = 1;
			ap_state_handling_storage_id_set(ApQ_para[0]);
			ap_browse_sts_set(BROWSE_UNMOUNT);
			ap_browse_stop_handle();

			#if(GP_UI == General_UI)
			{
				ap_state_handling_icon_show_cmd(ICON_INTERNAL_MEMORY, 0, 0);
				ap_state_handling_icon_clear_cmd(ICON_SD_CARD, 0, 0);
				/*
				ap_state_handling_icon_clear_cmd(ICON_PAUSE, ICON_PLAY, 0);
				ap_state_handling_icon_clear_cmd(ICON_PLAY1, ICON_PAUSE1, 0);
				ap_state_handling_icon_clear_cmd(ICON_PLAYBACK_PLAY, ICON_PLAYBACK_PAUSE, 0);
				ap_state_handling_icon_clear_cmd(ICON_PLAYBACK, ICON_PLAYBACK_MOVIE, 0);
				ap_state_handling_icon_show_cmd(ICON_PLAYBACK, 0, 0);
				*/
			}
			#endif
			ap_browse_file_name_clear();
			ap_state_handling_icon_clear_cmd(ICON_LOCKED, 0, 0);
			ap_state_handling_progress_bar_set(DPT_SHOW_NONE);
			ap_display_show_date_time(SHOW_TIME_NONE);
			ap_browse_volume_icon_clear_all();
			ap_browse_string_icon_clear();

			ap_browse_no_media_show(STR_NO_MEDIA);
			DBG_PRINT("[State Browse Mount FAIL]\r\n");
			break;

			
		//case MSG_APQ_MENU_KEY_ACTIVE:
		//case MSG_APQ_MODE:
		case MSG_APQ_RIGHT_LONG_KEY_ACTIVE:
		//case MSG_APQ_NEXT_KEY_ACTIVE:
			if(!g_browser_reply_action_flag)
			{
				OSTimeDly(1);
				msgQSend(ApQ, msg_id, NULL, 0, MSG_PRI_NORMAL);
				break;
			}

			//OSQPost(StateHandlingQ, (void *) STATE_SETTING);
			OSQPost(StateHandlingQ, (void *) STATE_PHOTO_CAPTURE);
			exit_flag = EXIT_BREAK;
			break;

		case MSG_APQ_LEFT_LONG_KEY_ACTIVE:
		case MSG_APQ_MODE_LONG_PRESS: 
			if(!g_browser_reply_action_flag)
			{
				OSTimeDly(1);
				msgQSend(ApQ, msg_id, NULL, 0, MSG_PRI_NORMAL);
				break;
			}
#if C_SPI_FLASH_DISK
			if (/*(ap_state_handling_storage_id_get() == NO_STORAGE) || */(browse_total_file_num == 0))
			{
				DBG_PRINT("no_storage mode long_press\r\n");
				break;
			}
#else
			if ((ap_state_handling_storage_id_get() == NO_STORAGE) || (browse_total_file_num == 0))
			{
				DBG_PRINT("no_storage mode long_press\r\n");
				break;
			}
#endif
			//go to lock and unlock
			OSQPost(StateHandlingQ, (void *) (STATE_SETTING | 0xAA000000));	//STATE_SETTING == 0x100
			exit_flag = EXIT_BREAK;
			break;
		


		case MSG_APQ_POWER_KEY_ACTIVE:
		case MSG_APQ_SW_RESET:
			ap_browse_exit(MSG_APQ_POWER_KEY_ACTIVE);
			switch(msg_id)
			{
				case MSG_APQ_POWER_KEY_ACTIVE:
					ap_state_handling_power_off(0);
				break;
				case MSG_APQ_SW_RESET:
					ap_state_handling_power_off(1);
				break;
			}
			break;
			
		case MSG_APQ_FUNCTION_KEY_ACTIVE:
			if(!g_browser_reply_action_flag)
			{
				OSTimeDly(1);
				msgQSend(ApQ, msg_id, NULL, 0, MSG_PRI_NORMAL);
				break;
			}

			if(func_key_act == 0)
			{
				ap_browse_func_key_active();
			}
			break;
		//case MSG_APQ_NEXT_KEY_ACTIVE:
		case MSG_APQ_RIGHT_KEY_ACTIVE:
			if(!g_browser_reply_action_flag)
			{
				OSTimeDly(1);
				msgQSend(ApQ, msg_id, &ApQ_para[0], sizeof(INT8U), MSG_PRI_NORMAL);
				break;
			}
			//ap_live_show_set(LIVE_BROWSE_GENERAL_SHOW);
			ap_browse_next_key_active(ApQ_para[0]);
			break;
		case MSG_APQ_NEXT_KEY_ACTIVE:
			break;
		//case MSG_APQ_PREV_KEY_ACTIVE:
		//case MSG_APQ_DELETE_KEY_ACTIVE:
			if(!g_browser_reply_action_flag)
			{
				OSTimeDly(1);
				//msgQSend(ApQ, msg_id, NULL, 0, MSG_PRI_NORMAL);
				break;
			}
			
			if(ap_browse_sts_get() & BROWSE_PLAYBACK_BUSY){
				break;
				}
			DBG_PRINT("**ap_browse_sts_get():%d\r\n",ap_browse_sts_get());
#if C_SPI_FLASH_DISK
			if(((ap_browse_sts_get() == 0)||(ap_state_handling_storage_id_get()== NO_STORAGE))&&value_browse_total_num()!= 0)
		{	
				
#else	
			if((ap_browse_sts_get() == 0 )||(ap_state_handling_storage_id_get()!= NO_STORAGE))
		{	
#endif
				//if (msg_id == MSG_APQ_DEL_ALL_ACTIVE)
				//	del_mode = 0;	// 1 : delete one   0: delete all
				//else
				//	del_mode = 1;	// 1 : delete one   0: delete all


				//del_mode = 1;	// 1 : delete one   0: delete all
				//close(browse_curr_avi.file_handle);
				OSQPost(StateHandlingQ, (void *) STATE_DEL_FILE);
				//msgQFlush(ApQ);
				
				exit_flag = EXIT_BREAK; 
				OSTimeDly(2);
			}
			break;


		case MSG_APQ_MENU_KEY_ACTIVE:
		//case MSG_APQ_MODE:
			if(!g_browser_reply_action_flag)
			{
				OSTimeDly(1);
				msgQSend(ApQ, msg_id, NULL, 0, MSG_PRI_NORMAL);
				break;
			}

			OSQPost(StateHandlingQ, (void *) STATE_VIDEO_RECORD);
			exit_flag = EXIT_BREAK;
			break;

		case MSG_STORAGE_SERVICE_BROWSE_REPLY:
			g_browser_reply_action_flag = 1;
			ap_browse_reply_action((STOR_SERV_PLAYINFO *) ApQ_para);
			break;

		case MSG_APQ_FORWARD_FAST_PLAY:
			if((ap_browse_sts_get() == 0) || (ap_browse_sts_get() & BROWSE_PLAYBACK_PAUSE))
			{ }
			else
			{
				INT8U	speed_temp;

				if(browser_play_speed >= 3)
				{
					browser_play_speed = 3;
					break;
				}

				browser_play_speed++;

				ap_browse_fast_play_icon_show(browser_play_speed);

				if(browser_play_speed >= 0)
				{
					if(ap_browse_get_curr_file_type() == TK_IMAGE_TYPE_WAV)
					{
						ap_state_audio_reverse_set(0);
						ap_state_audio_play_speed_set(browser_play_speed);
					}
					else
					{
						vid_dec_set_reverse_play(0);
						vid_dec_set_play_speed(0x10000 << browser_play_speed);
					}
				}
				else
				{
					speed_temp = ~browser_play_speed;
					if(ap_browse_get_curr_file_type() == TK_IMAGE_TYPE_WAV)
					{
						ap_state_audio_reverse_set(1);
						ap_state_audio_play_speed_set(speed_temp);
					}
					else
					{
						vid_dec_set_reverse_play(1);
						vid_dec_set_play_speed(0x10000 << speed_temp);
					}
				}
			}

			break;

		//case MSG_APQ_PREV_KEY_ACTIVE:
		case MSG_APQ_LEFT_KEY_ACTIVE:
			if(!g_browser_reply_action_flag)
			{
				OSTimeDly(1);
				msgQSend(ApQ, msg_id, &ApQ_para[0], sizeof(INT8U), MSG_PRI_NORMAL);
				break;
			}
			ap_live_show_set(LIVE_BROWSE_GENERAL_SHOW);
			ap_browse_prev_key_active(ApQ_para[0]);
			break;

		case MSG_APQ_BACKWORD_FAST_PLAY:
			if((ap_browse_sts_get() == 0) || (ap_browse_sts_get() & BROWSE_PLAYBACK_PAUSE))
			{ }
			else
			{
				INT8U	speed_temp;

				if(browser_play_speed <= -3)
				{
					browser_play_speed = -3;
					break;
				}

				browser_play_speed--;

				ap_browse_fast_play_icon_show(browser_play_speed);

				if(browser_play_speed >= 0)
				{
					if(ap_browse_get_curr_file_type() == TK_IMAGE_TYPE_WAV)
					{
						ap_state_audio_reverse_set(0);
						ap_state_audio_play_speed_set(browser_play_speed);
					}
					else
					{
						vid_dec_set_reverse_play(0);
						vid_dec_set_play_speed(0x10000 << browser_play_speed);
					}
				}
				else
				{
					speed_temp = ~browser_play_speed;
					if(ap_browse_get_curr_file_type() == TK_IMAGE_TYPE_WAV)
					{
						ap_state_audio_reverse_set(1);
						ap_state_audio_play_speed_set(speed_temp);
					}
					else
					{
						vid_dec_set_reverse_play(1);
						vid_dec_set_play_speed(0x10000 << speed_temp);
					}
				}
			}

			break;

#if(defined(C_ZHONGQIN_SPECIAL) && (C_ZHONGQIN_SPECIAL == CUSTOM_ON))
		case MSG_APQ_DEL_KEY_ACTIVE:
			msgQSend(StorageServiceQ, MSG_STORAGE_SERVICE_VIDEO_FILE_DEL, NULL, 0, MSG_PRI_NORMAL);
			g_browser_reply_action_flag = 0;
			break;

		case MSG_APQ_SELECT_FILE_DEL_REPLY:
			{
				INT8U data = 0;

				g_browser_reply_action_flag = 1;
				if(ApQ_para[0] == 0x55)
				{
					break;
				}

				msgQSend(ApQ, MSG_APQ_PREV_KEY_ACTIVE, &data, sizeof(INT8U), MSG_PRI_NORMAL);
			}
			break;
#endif

		case MSG_APQ_VOLUME_SHOW_END:
			ap_browse_volume_icon_clear_all();
			break;

		case MSG_APQ_MJPEG_DECODE_END:

			#if (Debug_playback == TRUE)
			 DBG_PRINT("receive MJPEG_DECODE_END	\r\n");
			#endif

			ap_browse_mjpeg_stop();
			ap_browse_mjpeg_play_end();
			close(browse_curr_avi.file_handle);

			g_browser_reply_action_flag = 0;
			search_type = STOR_SERV_SEARCH_ORIGIN;
			msgQSend(StorageServiceQ, MSG_STORAGE_SERVICE_BROWSE_REQ, (void *) &search_type, sizeof(INT32U), MSG_PRI_NORMAL);
			break;

		case MSG_APQ_CONNECT_TO_PC:
			state_browse_exit(msg_id);
			OSTimeDly(10);
			ap_state_handling_connect_to_pc(STATE_BROWSE);
			break;

		case MSG_APQ_DISCONNECT_TO_PC:
			ap_state_handling_disconnect_to_pc();
			OSTimeDly(10);
			video_encode_sensor_off();
			ap_browse_init(STATE_SETTING, play_index);
			break;

#if C_BATTERY_DETECT == CUSTOM_ON

		case MSG_APQ_BATTERY_LVL_SHOW:
			ap_state_handling_battery_icon_show(ApQ_para[0]);
			ap_browse_display_update_command(); // give DRAW command
			break;

		case MSG_APQ_BATTERY_CHARGED_SHOW:
			ap_state_handling_charge_icon_show(1);
			ap_browse_display_update_command(); // give DRAW command
			break;

		case MSG_APQ_BATTERY_CHARGED_CLEAR:
			ap_state_handling_charge_icon_show(0);
			ap_browse_display_update_command(); // give DRAW command
			break;

		case MSG_APQ_BATTERY_LOW_SHOW:
			ap_state_handling_clear_all_icon();
			ap_state_handling_str_draw_exit2();
			OSTimeDly(1);
			
			ap_state_handling_str_draw(STR_BATTERY_LOW, WARN_STR_COLOR);
			ap_state_handling_str_draw1(STR_PROMPT, WARN_STR_COLOR);
			msgQSend(PeripheralTaskQ, MSG_PERIPHERAL_TASK_BATTERY_LOW_BLINK_START, NULL, 0, MSG_PRI_NORMAL);
			break;
#endif // C_BATTERY_DETECT == CUSTOM_ON
#if C_SCREEN_SAVER == CUSTOM_ON

		case MSG_APQ_KEY_IDLE:
			ap_state_handling_lcd_backlight_switch(0);
			break;

		case MSG_APQ_KEY_WAKE_UP:
			ap_state_handling_lcd_backlight_switch(1);
			break;
#endif // C_SCREEN_SAVER == CUSTOM_ON

		case MSG_APQ_INIT_THUMBNAIL:
			if(!g_browser_reply_action_flag)
			{
				OSTimeDly(1);
				msgQSend(ApQ, msg_id, NULL, 0, MSG_PRI_NORMAL);
				break;
			}

			OSQPost(StateHandlingQ, (void *) STATE_THUMBNAIL);
			exit_flag = EXIT_BREAK;
			break;

		case MSG_APQ_USER_CONFIG_STORE:
			ap_state_config_store();
			break;

		case MSG_APQ_AUDIO_EFFECT_OK:
			if((ap_browse_sts_get() == 0) || (ap_browse_sts_get() & BROWSE_UNMOUNT))
			{
				if(g_browser_reply_action_flag)
				{
					if(ap_state_common_handling(MSG_APQ_AUDIO_EFFECT_OK) == 0)
					{
						func_key_act = 1;
					}
				}
			}

			break;

		case MSG_APQ_DISPLAY_DRAW_TIMER:
			break;

		case MSG_APQ_AUDIO_EFFECT_UP:
		case MSG_APQ_AUDIO_EFFECT_DOWN:
			break;

		case MSG_APQ_AUDIO_EFFECT_MODE:
		case MSG_APQ_AUDIO_EFFECT_MENU:
			mode_key_enabled = 1;
			break;

		case MSG_APQ_BACK_SENSOR_PLUG_IN:
		case MSG_APQ_BACK_SENSOR_PLUG_OUT:
			if(msg_id == MSG_APQ_BACK_SENSOR_PLUG_IN)
			{
				back_sensor_plug_status_set(1);

				//restoring from config
				DBG_PRINT("BACK SENSOR PLUG IN\r\n");
			#if C_REAR_ONLY == CUSTOM_OFF
				preview_mode = ap_state_config_display_mode_get();
			#else
				preview_mode = PREVIEW_MODE_REAR;
			#endif
			}
			else
			if(msg_id == MSG_APQ_BACK_SENSOR_PLUG_OUT)
			{
				back_sensor_plug_status_set(0);

				//storing config
				DBG_PRINT("BACK SENSOR PLUG OUT\r\n");

				//deactivate dual cam preview modes
			#if C_REAR_ONLY == CUSTOM_OFF
				ap_state_config_display_mode_set(PREVIEW_MODE_PIP_REAR);
				preview_mode = PREVIEW_MODE_FRONT;
			#else
				ap_state_config_display_mode_set(PREVIEW_MODE_REAR);
				preview_mode = PREVIEW_MODE_NONE;
			#endif
			}

			break;

		case MSG_APQ_BACK_A_CAR_ON:
			if(!g_browser_reply_action_flag)
			{
				OSTimeDly(1);
				msgQSend(ApQ, MSG_APQ_BACK_A_CAR_ON, NULL, 0, MSG_PRI_NORMAL);
				break;
			}

			DBG_PRINT("browse status BACK A CAR ON\r\n");
			OSQPost(StateHandlingQ, (void *) STATE_VIDEO_RECORD);
			exit_flag = EXIT_BREAK;
			msgQSend(ApQ, MSG_APQ_BACK_A_CAR_ON, NULL, 0, MSG_PRI_NORMAL);
			temp = BACK_A_CAR_KEY;
			msgQSend(PeripheralTaskQ, MSG_PERIPHERAL_TASK_KEY_REGISTER, &temp, sizeof(INT8U), MSG_PRI_NORMAL);
			break;

		#if defined(C_FIRMWARE_UPGRADE) && C_FIRMWARE_UPGRADE
		case MSG_STORAGE_FIRMWARE_UPGRADE:
			OSQPost(StateHandlingQ, (void *) STATE_FIRMWARE_UPGRADE);
			exit_flag = EXIT_BREAK;
			break;
		#endif // defined(C_FIRMWARE_UPGRADE) && C_FIRMWARE_UPGRADE

		default:
			break;
		}
	}

	state_browse_exit(msg_id);
}

void state_browse_exit(INT32U next_state_msg)
{
	INT8S     ret;
	STOR_SERV_PLAYINFO file_info_ptr;
	
	g_browser_reply_action_flag = 0;
	ap_browse_exit(next_state_msg);



	ap_state_handling_str_draw_exit();
	ap_state_handling_str_draw_exit1();
	ap_state_handling_str_draw_exit2();
	
	if((next_state_msg != MSG_APQ_INIT_THUMBNAIL) && (next_state_msg != MSG_APQ_CONNECT_TO_PC) && (next_state_msg != MSG_APQ_MENU_KEY_ACTIVE))
	{
		OSTimeDly(1);
	}

	if(mode_key_enabled == 1)
	{
		audio_effect_play(EFFECT_CLICK);
		mode_key_enabled = 0;
	}
	
	#if(defined(C_ZHONGQIN_SPECIAL) && (C_ZHONGQIN_SPECIAL == CUSTOM_ON))
		#if Browse_Close_Screen_Save
			ap_state_config_auto_off_TFT_BL_set(Pre_Screen_Save_Status);
		#endif
	#endif
	
	DBG_PRINT("Exit browse state\r\n");
}
INT16U value_browse_total_num(void)
{
	return browse_total_file_num;
}

